package d2_com.itheima.io;

import java.io.*;

/**
 * IO流 字符流
 */
public class Test3 {
    public static void main(String[] args) {
        /**
         * 文件字符输入流
         */

        /*//每次读取一个字符
        try (Reader f1 = new FileReader("F:\\Java code\\javasepro\\javasepro\\oop-app6\\5.txt")) {
            int c;
            while ((c = f1.read()) != -1) {
                System.out.print((char)c);
            }
        } catch (Exception e) {
           e.printStackTrace();
        }*/

        //每次读取多个字符内容
        try (Reader f1 = new FileReader("F:\\Java code\\javasepro\\javasepro\\oop-app6\\5.txt")) {
            char[] buffer = new char[3];
            int len;
            while ((len = f1.read(buffer)) != -1) {
                System.out.print(new String(buffer, 0, len));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        /**
         * 文件字符输出流
         */

        //
        try (Writer f2 = new FileWriter("oop-app6\\6.txt");){
            f2.write('a');
            f2.write(97);
            f2.write('六');
            f2.write("\r\n");
            f2.write("我是你爹");
            f2.write("\r\n");
            f2.write("我是你爹",0,2);
            f2.write("你爹");
            f2.write("\r\n");
            char[] buffer = {'黑', '马','程', '序','员'};
            f2.write(buffer);
            f2.write("\r\n");
            f2.write(buffer,0,2);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
